package com.ewhale.feitengguest.ui.user.message.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ewhale.feitengguest.R;
import com.ewhale.feitengguest.dto.ConversationDto;
import com.hyphenate.chat.EMMessage;
import com.hyphenate.easeui.ModelBean;
import com.hyphenate.util.DateUtils;
import com.simga.library.adapter.MBaseAdapter;
import com.simga.library.utils.StringUtil;
import com.simga.library.utils.glide.GlideUtil;

import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TudiAdapter extends MBaseAdapter<ConversationDto.ApprenticeDtoListBean> {


    public TudiAdapter(Context context, List<ConversationDto.ApprenticeDtoListBean> data) {
        super(context, data, R.layout.item_tudi);
    }

    @Override
    protected void newView(View convertView, int position) {
        convertView.setTag(new ViewHolder(convertView));
    }

    @Override
    protected void holderView(View convertView, ConversationDto.ApprenticeDtoListBean result, int position) {
        ViewHolder holder = (ViewHolder) convertView.getTag();
        GlideUtil.loadRoundPicture(result.getHeadPhoto(), holder.mIvAvatar, R.drawable.ease_default_avatar);
        holder.mTvName.setText(StringUtil.phone2Unknown(result.getPhone()));
        holder.mTvContent.setText("注册时间 ：" + result.getCreateTime());
//        if (result.getConversation() != null) {
//            EMMessage lastMessage = result.getConversation().getLastMessage();
//            if (lastMessage != null) {
//                holder.mTvUnRead.setVisibility(View.VISIBLE);
//                holder.mTvTime.setVisibility(View.VISIBLE);
////                holder.mTvContent.setVisibility(View.VISIBLE);
////                String content = null;
////                holder.mTvContent.setText(EaseSmileUtils.getSmiledText(mContext, EaseCommonUtils.getMessageDigest(lastMessage, mContext)),
////                        TextView.BufferType.SPANNABLE);
////                if (content != null) {
////                    holder.mTvContent.setText(content);
////                }
//                holder.mTvTime.setText(DateUtils.getTimestampString(new Date(lastMessage.getMsgTime())));
//                long unRead = result.getConversation().getUnreadMsgCount();
//                if (unRead > 0) {
//                    holder.mTvUnRead.setText(String.valueOf(unRead));
//                    holder.mTvUnRead.setVisibility(View.VISIBLE);
//                } else {
//                    holder.mTvUnRead.setVisibility(View.INVISIBLE);
//                }
//            } else {
//                holder.mTvUnRead.setVisibility(View.INVISIBLE);
//                holder.mTvTime.setVisibility(View.INVISIBLE);
////                holder.mTvContent.setVisibility(View.INVISIBLE);
//            }
//
//        } else {
//            holder.mTvUnRead.setVisibility(View.INVISIBLE);
//            holder.mTvTime.setVisibility(View.INVISIBLE);
////            holder.mTvContent.setVisibility(View.INVISIBLE);
//        }
    }

    class ViewHolder {
        @BindView(R.id.iv_avatar)
        ImageView mIvAvatar;
        @BindView(R.id.tv_name)
        TextView mTvName;
        @BindView(R.id.tv_content)
        TextView mTvContent;
        @BindView(R.id.tv_unRead)
        TextView mTvUnRead;
        @BindView(R.id.tv_time)
        TextView mTvTime;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
